<?php
/**
 * PHPTyrant CLI Stress Test Script
 *
 * Please start tokyo tyrant by 'ttserver -dmn' for daemon mode)
 * before running this script from the command line.
 *
 *
 * Test Results
 * ------------
 * 
 * Method: stress_test.php, fasttyrant class:
 * Task: 10K writing, 10K reading
 * Dataset: 
 *   $testkey = "test_".$i;
 *   $testdata = "testdata_".$i;
 * 
 * On-memory Hash   (*): 2.68, 2.82
 * On-memory B-Tree (*): 2.80, 2.53
 * Disk Hash     (.tch): 2.89, 2.55
 * Disk B-Tree   (.tcb): 3.02, 3.07
 * Disk Table    (.tct): 3.15, 3.43
 *  
 * PHP version 5
 *
 * @category  PHP
 * @package   Tokyo_Tyrant
 * @author    Tamas Kalman <ktamas77@gmail.com>
 * @license   BSD
 */

error_reporting(0);
$max_stress = 1000000;

require "../phptyrant.inc.php";
require "phptimer/timer.class.inc.php";

echo "PHPTyrant Stress Test ($max_stress)\n";

$timer = new Timer();

// $tyrant = new Tyrant(); // emulated PyTyrant
$tyrant = new FastTyrant(); // PHP optimized class

echo "Opening Tyrant...\n";
$tyrant->open();

echo "Writing ($max_stress)...\n";

$timer->start("put");
for ($i=0;$i<$max_stress;$i++) {
	$testkey = "test_".$i;
	$testdata = "testdatarewuioweruwero iweru weriouwerwerwero iuweruwer oiru weriouwer uoiwer weroirwuuerwoiwr_".$i;
	$tyrant->put($testkey, $testdata);
}
$timer->stop("put");

echo "Reading ($max_stress)...\n";

$timer->start("get");
for ($i=0;$i<$max_stress;$i++) {
	$testkey = "test_".$i;
	$testdata = "testdata_".$i;
	$var = $tyrant->get($testkey);
}
$timer->stop("get");

// -- not working - fix --
// $items = $tyrant->rnum();
// echo "Number of items in the DB: $items\n";

// -- not working - fix --
// echo "Vanishing DB...\n";
// $tyrant->vanish();

echo "Closing connection...\n";
$tyrant->close();

var_dump($timer->getAll());

echo "Done.\n";

?>